package main;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;


public class Register {
    public static Image PIG_STAY, PIG_RIGHT, PIG_LEFT,PIG_STEP_RIGHT, PIG_STEP_LEFT,
            HORSE_STAY, HORSE_LEFT, HORSE_RIGHT, HORSE_STEP_RIGHT, HORSE_STEP_LEFT;
    public static ArrayList<ArrayList> FUTURES;
    public static ArrayList<AbstractEntity> WALLS;// = new ArrayList<>();
    public static ArrayList<ArrayList> ENTITIES;
    public static ArrayList<Pig> PIGS = new ArrayList<>();
    public static ArrayList<Zombie> ZOMBIES = new ArrayList<>();
    public static ArrayList<Horse> HORSES = new ArrayList<>();
    public static ArrayList<ProjectileEntity> PROJECTILE_ENTITIES;// = new ArrayList<>();
    public static ArrayList<Player> PLAYERS;
    public static ArrayList<LivingEntity> EXCLUSIVE;
    public static AbstractEntity WALL,ANDESITE;
    public static Player PLAYER;
    public static LivingEntity PIG,ZOMBIE;
    public static ProjectileEntity ARROW;
    public static Image GRASS;
        //locateImage("grass");
//    public static String "/" = Fil;


    public static void register() throws IOException{

        GRASS = locateImage("grass");
        PIG_STAY = locateImage("pig/pig_stay");
        PIG_LEFT = locateImage("pig/pig_left");
        PIG_RIGHT = locateImage("pig/pig_right");
        PIG_STEP_RIGHT = locateImage("pig/pig_step_right");
        PIG_STEP_LEFT = locateImage("pig/pig_step_left");

        HORSE_STAY = locateImage("horse/horse_stay");
        HORSE_LEFT = locateImage("horse/horse_left");
        HORSE_RIGHT = locateImage("horse/horse_right");
        HORSE_STEP_RIGHT = locateImage("horse/horse_step_right");
        HORSE_STEP_LEFT = locateImage("horse/horse_step_left");

        ARROW = new Arrow(locateImage("man"), locateImage("pig"));

        ARROW.setPos(512,256);

        String name = "player";
        PLAYER = new Player(
                locateImage(name + "/" + name + "_left"),
                locateImage(name + "/" + name + "_step_left"),
                locateImage(name + "/" + name + "_right"),
                locateImage(name + "/" + name + "_step_right"),
                locateImage(name + "/" + name + "_stay")
        );
        PLAYER.setPos(0,0);






        name = "zombie";
        ZOMBIE = new Zombie(
                locateImage(name + "/" + name + "_left"),
                locateImage(name + "/" + name + "_step_left"),
                locateImage(name + "/" + name + "_right"),
                locateImage(name + "/" + name + "_step_right"),
                locateImage(name + "/" + name + "_stay")
        );
        ZOMBIE.setPos(100,100);


        WALL = new Wall(locateImage("man"));
        WALL.setBox(64,64,128,128);

//        name = "zombie";
//        ZOMBIE = new Zombie(
//                locateImage(name + "/" + name + "_left"),
//                locateImage(name + "/" + name + "_step_left"),
//                locateImage(name + "/" + name + "_right"),
//                locateImage(name + "/" + name + "_step_right")
//        );

        //Sprite wall2 = getSprite("man.png"); wall2.setBox(128,128,192,256);

        WALLS = new ArrayList<>(Arrays.asList(

        ));
        EXCLUSIVE = new ArrayList<>(Arrays.asList(
            ZOMBIE
        ));
        PLAYERS = new ArrayList<>(Arrays.asList(
                PLAYER
        ));
        PROJECTILE_ENTITIES = new ArrayList<>(Arrays.asList(

        ));
        ENTITIES = new ArrayList<>();
        ENTITIES.add(EXCLUSIVE);
        ENTITIES.add(PIGS);
        ENTITIES.add(ZOMBIES);
        ENTITIES.add(HORSES);


        FUTURES = new ArrayList<ArrayList>();
        FUTURES.add(WALLS);
        FUTURES.add(PROJECTILE_ENTITIES);

    }






    public static Image collect(String name) throws IOException {
        List<String> images = Arrays.asList("_left","_step_left","_right","_step_right");
        for (String image : images) {
            return locateImage(name + "/" + name + image);
        }
        return null;
    }

    public static Image locateImage (String path) throws IOException {


        return ImageIO.read(Objects.requireNonNull(Register.class.getResourceAsStream(
                 "/resources/" + path + ".png")));

    }
}
